package com.zeroone.star.seata.service.impl;

import com.zeroone.star.seata.service.TransService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Random;

/**
 * @Description 测试服务实现类
 * @Author lyx
 * @since 2024/11/9 15:11
 */

@Service
@GlobalTransactional
public class TransServiceImpl implements TransService {

    private final Random random = new Random();

    @Resource
    JdbcTemplate jdbcTemplate;

    @Override
    public int saveData() {
        if(random.nextBoolean()){
            String sql = "UPDATE `test`.`sample` SET  `name` = 'huhu' WHERE `id` = 2";
            return jdbcTemplate.update(sql);
        }
        return 0;
    }
}
